{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="status" lay-search="">
                                <option  value="">不限状态</option>
                                <option  value="1">审核中</option>
                                <option  value="2">审核通过</option>
                                <option  value="3">审核失败</option>
                                <option  value="4">超时下架</option>
                                <option  value="5">众筹成功</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="众筹标题/发起人"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <ul class="img_view">
                            {{# if(d.fund_imgs.length > 0){ }}
                            <li><img src="{{d.fund_imgs[0]}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/></li>
                            {{# if(d.fund_imgs.length >= 1){ }}
                            {{# for(var i=1;i<d.fund_imgs.length;i++){  }}
                            <li style="display:none;"><img src="{{d.fund_imgs[i]}}" ></li>
                            {{# } }}
                            {{# } }}
                            {{# } }}
                        </ul>
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staTpl">
                        {{# if(d.fund_status == 1){ }}
                        审核中
                        {{# }else if(d.fund_status == 2){ }}
                        审核通过
                        {{# }else if(d.fund_status == 3){ }}
                        审核失败
                        {{# }else if(d.fund_status == 4){ }}
                        超时下架
                        {{# }else{ }}
                        众筹成功
                        {{# } }}
                    </script>
                    <script type="text/html" id="hotBar">
                        <input type="checkbox" value="{{d.fund_id}}" lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff"{{ d.fund_country == 2 ? 'checked' : '' }}  >
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.fund_status == 1){ }}
                        <a href="javascript:;" onclick="check({{d.fund_id}})"  class="btn btn-primary btn-xs m-r-xs">审核</a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.href('{:url('look')}?id={{d.fund_id}}')" class="btn btn-primary btn-xs m-r-xs">查看众筹人员</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("fund/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'fund_title', width: '', title: '众筹标题', align: 'center'}
                , {field: 'fund_plan', width: '', title: '计划众筹金额', align: 'center'}
                , {field: 'fund_imgs', width: 90, title: '商品图片', align: 'center', templet: '#imgTpl'}
                , {field: 'fund_introduction', width: '', title: '简介', align: 'center'}
                , {field: 'fund_money', width: '', title: '已筹金额', align: 'center'}
                , {field: 'fund_check_time', width: '', title: '发起时间', align: 'center'}
                , {field: 'fund_end_time', width: '', title: '终止时间', align: 'center'}
                , {field: 'fund_join', width: '', title: '参加人数', align: 'center'}
                , {field: 'user_username', width: '', title: '发起人', align: 'center'}
                , {field: 'user_phone', width: '', title: '手机号', align: 'center'}
                , {field: 'district', width: '', title: '地区', align: 'center'}
                , {field: 'fund_status', width: '', title: '状态', align: 'center',templet:'#staTpl'}
                , {fixed: 'right', width: 100, title: '全国推广', align: 'center', templet: '#hotBar'}
                , {fixed: 'right', width: 200, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]],
            done: function (res, curr, count) {
                $('.img_view').viewer();
            }
        });

        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("country")}',obj);
        });
    });

    function check(p_id) {
        layer.confirm('审核是否通过吗?', {
            icon: 3,
            title:'提示',
            btn: ['通过', '驳回'],
            btn2:function(index){
                send(p_id,3);
                layer.close(index);
            }}, function(index){
            send(p_id,2);
            layer.close(index);
        });
    }
    function send(p_id,type){
        $.ajax({
            url: "{:url('doCheck')}",
            type: "post",
            dataType: "json",
            data: {fund_id:p_id,type:type},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>